package cn.edu.sjtu.literature.db.mapping;

import java.sql.ResultSet;
import java.sql.SQLException;

import cn.edu.sjtu.literature.entity.User;
import cn.edu.sjtu.literature.enumtype.UserType;

public class UserResultMappingCallback implements ResultMappingCallback<User> {

	@Override
	public User doResultMapping(ResultSet rs) throws SQLException {
		User user = new User();
		user.setId(rs.getInt("id"));
		user.setUsername(rs.getString("username"));
		user.setPassword(rs.getString("password"));
		user.setName(rs.getString("name"));
		Integer typeId = rs.getInt("type");
		user.setUserType(UserType.getUserType(typeId));
		user.setCreated(rs.getTimestamp("created_date"));
		user.setCreatedBy(rs.getInt("created_by"));
		user.setModified(rs.getTimestamp("modified_date"));
		user.setModifiedBy(rs.getInt("modified_by"));
		return user;
	}

}
